<template>
  <div class="box">
    <el-container>
      <!-- 顶部 -->
      <el-header>
        <div class="headerbox">
          <img src="../../public/LAG7Z.jpg" alt="" />
          <h3>电商后台管理系统</h3>
          <el-button class="btn" type="info" @click="quit">退出</el-button>
        </div>
      </el-header>
      <el-container>
        <!-- 侧边 -->
        <el-aside :width="flag ? '60px' : '201px'">
          <el-menu
            :default-active="$route.path"
            background-color="#23232f"
            text-color="#fff"
            active-text-color="#f26027"
            unique-opened
            :collapse="flag"
            :collapse-transition="false"
            router
          >
            <div class="iconbox">
              <i
                :class="flag ? 'el-icon-caret-right' : 'el-icon-caret-left'"
                @click="flag = !flag"
              ></i>
            </div>
            <!-- 用户管理 -->
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-user-solid"></i>
                <span>用户管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/users">
                  <i class="el-icon-menu"></i>
                  <span slot="title">用户列表</span>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
            <!-- 权限管理 -->
            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-s-claim"></i>
                <span>权限管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/roles">
                  <i class="el-icon-menu"></i>
                  <span slot="title">角色列表</span>
                </el-menu-item>
                <el-menu-item index="/rights">
                  <i class="el-icon-menu"></i>
                  <span slot="title">权限列表</span>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <!-- 商品管理 -->
            <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-s-goods"></i>
                <span>商品管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/goods">
                  <i class="el-icon-menu"></i>
                  <span slot="title">商品列表</span>
                </el-menu-item>
                <el-menu-item index="/params">
                  <i class="el-icon-menu"></i>
                  <span slot="title">分类列表</span>
                </el-menu-item>
                <el-menu-item index="/categories">
                  <i class="el-icon-menu"></i>
                  <span slot="title">商品分类</span>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <!-- 订单管理 -->
            <el-submenu index="4">
              <template slot="title">
                <i class="el-icon-s-order"></i>
                <span>订单管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/orders">
                  <i class="el-icon-menu"></i>
                  <span slot="title">订单列表</span>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <!-- 数据统计 -->
            <el-submenu index="5">
              <template slot="title">
                <i class="el-icon-s-marketing"></i>
                <span>数据统计</span>
              </template>
              <el-menu-item index="/report">
                <i class="el-icon-menu"></i>
                <span slot="title">数据报表</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 展示区 -->
        <el-main>
          <el-breadcrumb v-show="shhi" separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/welcome' }"
              >首页</el-breadcrumb-item
            >
            <el-breadcrumb-item>{{ site1 }}</el-breadcrumb-item>
            <el-breadcrumb-item>{{ site2 }}</el-breadcrumb-item>
          </el-breadcrumb>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  name: "APP",
  data() {
    return {
      path: "", //路径
      flag: false, //侧边菜单折叠默认状态
      shhi: true, // 控制面包屑显示隐藏
      site1: "", //位置1
      site2: "", //位置2
    };
  },
  methods: {
    quit() {
      //退出
      //删除token并退出
      sessionStorage.removeItem("token");
      this.$router.push("/login");
    },
  },
  watch: {
    //监听属性 监听路由变化
    $route: {
      handler(val) {
        // console.log(val);
        if (val.path == "/welcome") {
          this.shhi = false;
        } else {
          this.shhi = true;
        }
        if (val.path == "/users") {
          this.site1 = "用户管理";
          this.site2 = "用户列表";
        } else if (val.path == "/roles") {
          this.site1 = "权限管理";
          this.site2 = "角色列表";
        } else if (val.path == "/rights") {
          this.site1 = "权限管理";
          this.site2 = "权限列表";
        } else if (val.path == '/goods'){
          this.site1 = "商品管理";
          this.site2 = "商品列表";
        } else if(val.path == '/params'){
          this.site1 = "商品管理";
          this.site2 = "参数列表";
        } else if(val.path == '/categories'){
          this.site1 = "商品管理";
          this.site2 = "商品分类";
        } else if(val.path == '/goods/add'){
          this.site1 = "商品管理";
          this.site2 = "添加商品"
        } else if(val.path == '/orders'){
          this.site1 = '订单管理';
          this.site2 = '订单列表'
        } else if(val.path == '/report'){
          this.site1 = '数据统计';
          this.site2 = '数据报表'
        }
      },
      //一进入页面就执行
      immediate: true,
      //深度观察监听
      deep: true,
    },
  },
  created() {},
  mounted() {},
};
</script>
<style lang="scss" scoped>
html,body{
  height: 100%;
}
.box{
  height: 100%;
}
.el-container {
  height: 100%;
}

.el-header,
.el-footer {
  background-color: #23232f;
  color: #333;
  padding: 0;
}

.el-aside {
  background-color: #23232f;
  color: #333;
  // height: 100%;
}
::v-deep .el-menu-item-group__title {
  padding: 0px !important;
}

.el-main {
  background-color: white;
  color: #333;
  animation: bg-color 20s infinite;
  -webkit-animation: bg-color 20s infinite;

//   @-webkit-keyframes bg-color {

//     0% { background-color: #e74c3c; }

// 10% { background-color: #e76f3c; }

// 20% { background-color: #f1c40f; }

// 30% { background-color: #b1e73c; }

// 40% { background-color: #1abc9c; }

// 50% { background-color: #3498db; }

// 60% { background-color: #0a19ec; }

// 70% { background-color: #7b0aec; }

// 80% { background-color: #e223f0; }

// 90% { background-color: #ea148d; }

// 100% { background-color: #e61414; }

// }

// @keyframes bg-color {

//   0% { background-color: #e74c3c; }

// 10% { background-color: #e76f3c; }

// 20% { background-color: #f1c40f; }

// 30% { background-color: #b1e73c; }

// 40% { background-color: #1abc9c; }

// 50% { background-color: #3498db; }

// 60% { background-color: #0a19ec; }

// 70% { background-color: #7b0aec; }

// 80% { background-color: #e223f0; }

// 90% { background-color: #ea148d; }

// 100% { background-color: #e61414; }

// }
}

body > .el-container {
  margin-bottom: 40px;
}
.headerbox {
  // border: 1px solid red;
  color: white;
  display: flex;
  left: 0px;
  position: relative;
  img {
    width: 55px;
    height: 55px;
    border-radius: 50%;
    margin-top: 2px;
  }
  h3 {
    margin-top: 15px;
    margin-left: 10px;
  }
  .btn {
    position: absolute;
    right: 10px;
    top: 10px;
  }
}
.el-menu {
  height:100vh;
}
i {
  color: white;
}
.iconbox {
  height: 20px;
  // border: 1px solid red;
  line-height: 20px;
  margin-left: 22px;
  font-size: 20px;
}
</style>
